home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Dev / Orbit_SRC / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-27  |  2.1 KB  |  99 lines

  1. /*
  2.     Amiga port by Oliver Gantert
  3.  
  4.     28.04.2000 - fixed some compiler warnings
  5. */
  6. /*
  7.  
  8. ORBIT, a freeware space combat simulator
  9. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  24.  
  25. */
  26.  
  27. #include "orbit.h"
  28.  
  29. double Time ()
  30. {
  31.   static double oldtime=0.0;
  32.   double newtime, elapsed;
  33.  
  34.   newtime = glutGet (GLUT_ELAPSED_TIME);
  35.   elapsed = newtime - oldtime;
  36.   oldtime = newtime;
  37.  
  38.   return (elapsed/1000.0);
  39. }
  40.  
  41. void InitTimer()
  42. /*
  43.  *  Check for and initialize the performance timer
  44.  */
  45. {
  46.   #ifdef WIN32
  47.   /* This gives a compiler warning; not completely sure why */
  48.   if (!QueryPerformanceFrequency (&ticks_per_sec)) exit (0);
  49.   #endif
  50.   last_ticks = 0;
  51. }
  52.  
  53. int DeltaTime()
  54. /*
  55.  *  Figure out how much time has elapsed since the last time we were called
  56.  */
  57. {
  58.   #ifdef WIN32
  59.   _int64 ticks, elapsed;
  60.   #else
  61.   int ticks, elapsed;
  62.   #endif
  63.  
  64.   if (paused)
  65.   {
  66.     deltaT = 0.0;
  67.     return 0;
  68.   }
  69.  
  70.   #ifdef WIN32
  71.   /* This gives a compiler warning; not completely sure why */
  72.   QueryPerformanceCounter (&ticks);
  73.   #else
  74.   ticks = glutGet (GLUT_ELAPSED_TIME);
  75.   #endif
  76.  
  77.   if (last_ticks == 0)
  78.   {
  79.     deltaT = 0.0;
  80.   }
  81.   else
  82.   {
  83.     elapsed = ticks - last_ticks;
  84.     #ifdef WIN32
  85.     deltaT = ((double) elapsed) / ((double) ticks_per_sec);
  86.     #else
  87.     deltaT = ((double) elapsed) / 1000.0;
  88.     #endif
  89.   }
  90.  
  91.   /* If more than maximum, slow things down */
  92.   if (deltaT > MAXDELTAT) deltaT = MAXDELTAT;
  93.  
  94.   absT += deltaT;
  95.   last_ticks = ticks;
  96.  
  97.   return 0;
  98. }
  99.